﻿// Mixin class that creates a content component from the configuration
define([
'Xjs/core/util',
// Ensure the creation of the global Xjs
'Xjs/app'
],
function (util) {
    'use strict';

    var type = 'contentHolder', // Use the type registration to avoid recreating the type
    ContentHolder = Xjs.getType(type);

    if (ContentHolder) { // It has been already loaded
        return ContentHolder;
    }

    // Renders the html from a component
    ContentHolder = util.define({
        type: type, // Set the type

        initialize: function (conf) {

            conf = conf || {};

            // Whether the content needs to be added to the children or not
            var contentIncluded = conf.contentIncluded || this.contentIncluded;

            if (conf.content) {
                var content;
                if (util.isString(conf.content)) {
                    content = Xjs.create('content', {
                        content: conf.content,
                        binder: conf.binder
                    }, this);
                }
                else {
                    if (conf.type) {
                        content = Xjs.create(conf.type, conf.content, this);
                    }
                    else {
                        var type = this.defaultChildType || 'content';
                        content = Xjs.create(type, conf.content, this);
                    }
                }

                this.content = content;

                if (contentIncluded) {
                    this.addChild(content);
                }
            }
        }

    });

    Xjs.registerType(ContentHolder);

    return ContentHolder;
});